﻿using System;
using Uber.Core.Service;

namespace Uber.Service
{
    public static class SerialGenerator
    {
        private static readonly Random r;
        static SerialGenerator()
        {
            r = new Random();
        }

        public static string Do()
        {
            return string.Format("{0}-{1}-{2}-{3}", GetWord(3), GetWord(3), GetWord(3), GetWord(3));
        }

        public static string GetWord(int l)
        {
            var passwordLength = l;
            const string allowedChars = "OOO999777333ABCDEFGHJKLMNOPQRSTUVWCYZ1235789OOO";

            var chars = new char[passwordLength];

            for (var i = 0; i < passwordLength; i++)
                chars[i] = allowedChars[r.Next(0, allowedChars.Length - 1)];

            return new string(chars);
        }
    }

    public class PasswordGenerator : IPasswordGenerator
    {
        public string CreateRandomPassword()
        {
            const int passwordLength = 1000;
            const string allowedChars = "0123456789abcdefghijkmnopqrstuvwxyzABCDEFGH­JKLMNOPQRSTUVWXYZ";
            var randNum = new Random();
            var chars = new char[passwordLength];

            for (var i = 0; i < passwordLength; i++)
            {
                chars[i] = allowedChars[(int)((allowedChars.Length) * randNum.NextDouble())];
            }

            var s = new string(chars);

            var x = new Random().Next(900);

            return s.Substring(x, 50);
        }
    }
}